#ifndef __SUBSYSTEM_SCRIPTING_HPP__
# define __SUBSYSTEM_SCRIPTING_HPP__

# include <boost/shared_ptr.hpp>
# include <boost/noncopyable.hpp>

# include <sstream>
# include <string>

struct lua_State;

class f_engine_t;
class render_t;

/**
 * @brief Describes script-type resource.
 */
struct script_t : private boost::noncopyable
{
    static boost::shared_ptr<script_t> create(boost::shared_ptr<std::stringstream> &stream);

    std::string source_;
};

/**
 * @brief Describes isolated lua scripting instance.
 * @remarks
 *      Such instance can be enriched with required functionality
 *      by registering corresponding API.
 */
class scripting_instance_t : private boost::noncopyable
{
public:
    /**
     * @brief Creates scripting instance from lua script filename.
     */
    static boost::shared_ptr<scripting_instance_t> create(f_engine_t *engine, const std::string &script_name);

    void start(); /*override*/

    ~scripting_instance_t();

    /**
     * @brief Just run script.
     */
    bool run_script();

    /** @brief Different API which can be registered in scripting instance.*/
    /** {@ */
    void register_common();
    void register_render_api();
    void register_object_api();
    /** @} */

private:
    scripting_instance_t(f_engine_t *engine);

    lua_State *L_;

    boost::shared_ptr<script_t> script_;

    f_engine_t *engine_;
};

#endif //__SUBSYSTEM_SCRIPTING_HPP__
